﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using VisualPoint.Controls.Actions;
using VisualPoint.Controls.Commands;
using VisualPoint.Controls.Views;

namespace VisualPoint.Controls.Models
{
    public abstract class BaseActionModel : BaseModel, IEdit
    {
        #region Constructor

        public BaseActionModel()
        {
            _editActionCommand = new EditCommand(this);
        }

        #endregion

        #region Methods

        public abstract BaseAction GetAction();

        public abstract bool? EditItem();

        public abstract bool? AddItem();

        #endregion

        #region IEditAction

        public void Edit()
        {
            EditItem();
        }

        private EditCommand _editActionCommand;
        public EditCommand EditCommand
        {
            get
            {
                return _editActionCommand;
            }
        }

        #endregion
    }

    public class BaseActionModel<TA, TE> : BaseActionModel
        where TA : BaseAction, new()
        where TE : Window, IActionEditor<TA>, new()
    {

        #region Properties

        private TA _action;
        public TA Action
        {
            get
            {
                return _action;
            }
            set
            {
                _action = value;
                DoPropertyChanged("Action");
            }
        }

        #endregion

        #region Methods

        public override bool? AddItem()
        {
            Action = new TA();
            Action.InitializeNew();
            return ShowEditor();
        }

        public override bool? EditItem()
        {
            return ShowEditor();
        }

        public void DeleteItem()
        {

        }

        private bool? ShowEditor()
        {
            TE editor = new TE();
            editor.Action = Action;
            return editor.ShowDialog();
        }

        #endregion


        public override BaseAction GetAction()
        {
            return Action;
        }
    }
}
